import { API_CONFIG, CONFIG_VERSION } from '../config/constants';

/**
 * API路径验证和调试工具
 */
export class ApiPathValidator {
    /**
     * 打印所有API路径配置
     */
    static printAllPaths() {
        console.group('🔍 API路径配置检查');
        
        console.log('📍 基础配置:');
        console.log('  CONFIG_VERSION:', CONFIG_VERSION);
        console.log('  BASE_URL:', API_CONFIG.BASE_URL);
        console.log('  TIMEOUT:', API_CONFIG.TIMEOUT);
        
        console.log('\n💬 聊天相关API:');
        console.log('  CHAT_STREAM_URL:', API_CONFIG.CHAT_STREAM_URL);
        console.log('  CHAT_HISTORY_URL:', API_CONFIG.CHAT_HISTORY_URL);
        
        console.log('\n👥 会话管理API:');
        console.log('  CREATE_SESSION_URL:', API_CONFIG.CREATE_SESSION_URL);
        console.log('  GET_SESSIONS_URL:', API_CONFIG.GET_SESSIONS_URL);
        
        const testSessionId = 'test-session-id-123';
        console.log('\n🔧 动态路径示例 (sessionId: ' + testSessionId + '):');
        console.log('  DELETE_SESSION_URL:', API_CONFIG.DELETE_SESSION_URL(testSessionId));
        console.log('  UPDATE_SESSION_URL:', API_CONFIG.UPDATE_SESSION_URL(testSessionId));
        console.log('  COPY_SESSION_URL:', API_CONFIG.COPY_SESSION_URL(testSessionId));
        
        console.log('\n🔄 兼容性函数:');
        console.log('  getSessionDetail:', API_CONFIG.getSessionDetail(testSessionId));
        console.log('  copySession:', API_CONFIG.copySession(testSessionId));
        
        console.groupEnd();
    }
    
    /**
     * 验证特定会话ID的路径
     */
    static validateSessionPaths(sessionId) {
        console.group(`🔍 会话路径验证 (ID: ${sessionId})`);
        
        const paths = {
            '删除会话': API_CONFIG.DELETE_SESSION_URL(sessionId),
            '更新会话': API_CONFIG.UPDATE_SESSION_URL(sessionId),
            '复制会话': API_CONFIG.COPY_SESSION_URL(sessionId)
        };
        
        Object.entries(paths).forEach(([action, url]) => {
            console.log(`${action}: ${url}`);
            
            // 验证URL格式
            if (!url.includes('/session/sessions/')) {
                console.warn(`⚠️ ${action} 路径可能不正确，期望包含 '/session/sessions/'`);
            }
            
            if (!url.includes(sessionId)) {
                console.error(`❌ ${action} 路径缺少会话ID`);
            }
        });
        
        console.groupEnd();
        return paths;
    }
    
    /**
     * 检查路径一致性
     */
    static checkConsistency() {
        console.group('🔍 路径一致性检查');
        
        const testId = 'test-123';
        const newPath = API_CONFIG.DELETE_SESSION_URL(testId);
        const oldPath = API_CONFIG.getSessionDetail(testId);
        
        console.log('新路径函数:', newPath);
        console.log('旧路径函数:', oldPath);
        
        if (newPath === oldPath) {
            console.log('✅ 路径一致性检查通过');
        } else {
            console.warn('⚠️ 新旧路径函数返回不同的结果');
        }
        
        console.groupEnd();
    }
}

// 开发环境下自动运行路径检查
if (process.env.NODE_ENV === 'development') {
    // 延迟执行，确保在组件加载后运行
    setTimeout(() => {
        ApiPathValidator.printAllPaths();
        ApiPathValidator.checkConsistency();
    }, 1000);
}